<!-- 加载头文件 -->
<include file="Public/header" />

     <div class="headerContent">
            <div class="pageName">
                <p>确认地址</p>
            </div>
            <div class="headerStepRight">
                <img src="__PUBLIC__/children/images/title3.png">
                <ul>
                    <li><a class="overstep" href="__PUBLIC__/children/#">我的购物车</a></li>
                    <li><a class="overstep" href="__PUBLIC__/children/#">确定订单</a></li>
                    <li><a class="overstep" href="__PUBLIC__/children/#">确定地址</a></li>
                    <li><a href="__PUBLIC__/children/#">确定提交</a></li>
                </ul>
            </div>
        </div>
    
    <div class="main">
		
		
	</div>
    
    
 <!-- 加载尾文件 -->
<include file="Public/footer" />


<script src="__PUBLIC__/children/js/jquery-1.8.3.min.js"></script>

<script type="text/javascript">
	
	$(function(){
		dianji();
	
		function shujuall(){
		
			$.post("http://localhost/git/thinkphpkxs/thinkphpkxs01/index.php/Home/Sureaddress/addresslist", { "func": "getNameAndTime" },function(data){
		
				var str = ''
				for(var i=0;i<data.length;i++){
					str += '<div class="maincontent2"><div class="maincontenttop"><div class="maincontenttopleft"><a href="#">地址详情</a></div></div><div class="maincontentbottom"><div class="maincontentleft"><div>收货人：</div><div>所在地区：</div><div>地址：</div><div>手机：</div><div>固定电话：</div><div>电子邮箱：</div></div><div class="maincontentright">'
					 str += "<div class='consignee'>"+data[i].shouhuoren+"</div>"
					 str += "<div class='location'>"+data[i].address+"</div>"
					 str += "<div class='address'>"+data[i].detailaddress+"</div>"
					 str += "<div class='phonenumber'>"+data[i].phone+"</div>"
					 str += "<div class='Fixedtelephone'>"+data[i].tel+"</div>"
					 if(data[i].status==1){
						str += "<div class='maincontentrightbottom'><span class='email'>"+data[i].email+"</span><span class='editor' style='cursor:pointer'>编辑</span><span style='cursor:pointer' class='default selectedA' >设为默认</span>"
					 }else{
						str += "<div class='maincontentrightbottom'><span class='email'>"+data[i].email+"</span><span class='editor' style='cursor:pointer'>编辑</span><span style='cursor:pointer' class='default' >设为默认</span>"
					 }
					 str += "<input type='hidden' class='idcard' name='id' value='"+data[i].id+"'/><input type='hidden' class='stu' name='status' value='"+data[i].status+"'/><input type='hidden' class='idcard' name='id' value='"+data[i].p_id+"'/>"
					 str += "</div></div></div></div>"
				}
				str +='<div class="maincontent4"><a href="{:U('Sureorder/Sureorder')}">上一步</a>&nbsp;<a href="{:U('Submitpay/nowpay')}">下一步</a></div>'
				
				$(".main").html(str);
				
				$(".default").each(function(){
				
					var obj = $(this);
					
					obj.click(function(){
						var id = $(this).next().val();
						var status = $(this).next().next().val();
						var p_id = $(this).next().next().next().val();
						var url = "{:U('Sureaddress/changeAddress')}";
						$.ajax({
							  type: "POST",
							  url: url,
							  data: "id="+id+"&status="+status+"&p_id="+p_id,
							  success: function(msg){
							  //console.log(msg);
								
							  shujuall();
							  
							 //alert( "Data Saved: " + msg );
						   }
						});
					})
					
				
				})
				
			}, "json");
		
		}
	
		function dianji(){
			
			$.post("http://localhost/git/thinkphpkxs/thinkphpkxs01/index.php/Home/Sureaddress/addresslist", { "func": "getNameAndTime" },function(data){
		
			
				var str = ''
				for(var i=0;i<data.length;i++){
					str += '<div class="maincontent2"><div class="maincontenttop"><div class="maincontenttopleft"><a href="#">地址详情</a></div></div><div class="maincontentbottom"><div class="maincontentleft"><div>收货人：</div><div>所在地区：</div><div>地址：</div><div>手机：</div><div>固定电话：</div><div>电子邮箱：</div></div><div class="maincontentright">'
					 str += "<div class='consignee'>"+data[i].shouhuoren+"</div>"
					 str += "<div class='location'>"+data[i].address+"</div>"
					 str += "<div class='address'>"+data[i].detailaddress+"</div>"
					 str += "<div class='phonenumber'>"+data[i].phone+"</div>"
					 str += "<div class='Fixedtelephone'>"+data[i].tel+"</div>"
					 
					 if(data[i].status==1){
						str += "<div class='maincontentrightbottom'><span class='email'>"+data[i].email+"</span><span class='editor' style='cursor:pointer'>编辑</span><span style='cursor:pointer' class='default selectedA' >设为默认</span>"
					 }else{
						str += "<div class='maincontentrightbottom'><span class='email'>"+data[i].email+"</span><span class='editor' style='cursor:pointer'>编辑</span><span style='cursor:pointer' class='default' >设为默认</span>"
					 }
					
					 str += "<input type='hidden' class='idcard' name='id' value='"+data[i].id+"'/><input type='hidden' class='stu' name='status' value='"+data[i].status+"'/><input type='hidden' class='idcard' name='id' value='"+data[i].p_id+"'/>"
					 str += "</div></div></div></div>"
				}
				str +='<div class="maincontent4"><a href="{:U('Sureorder/Sureorder')}">上一步</a>&nbsp;<a href="{:U('Submitpay/nowpay')}">下一步</a></div>'
				
				$(".main").html(str);
				
				$(".default").each(function(){
				
					var obj = $(this);
					
					obj.click(function(){
						var id = $(this).next().val();
						var status = $(this).next().next().val();
						var p_id = $(this).next().next().next().val();
						var url = "{:U('Sureaddress/changeAddress')}";
						$.ajax({
							  type: "POST",
							  url: url,
							  data: "id="+id+"&status="+status+"&p_id="+p_id,
							  success: function(msg){
							  //console.log(msg);
								
							  shujuall();
							  
							 //alert( "Data Saved: " + msg );
						   }
						});
					})
					
				
				})
				
				
			}, "json");
			
		}

	})
		
	
</script>

</div>
</body>

<script src="__PUBLIC__/children/js/common.js"></script>
</html>